{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "outputs": [],
   "source": [
    "def cost(W: torch.Tensor, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:\n",
    "    x = x.unsqueeze(-1)\n",
    "    y = y.unsqueeze(-1)\n",
    "    return torch.mean(torch.square(W * x - y), (0, ))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "outputs": [],
   "source": [
    "x = torch.tensor([1., 2., 3.])\n",
    "y = torch.tensor([1., 2., 3.])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([4.6667, 4.6667, 4.6667])\n",
      "tensor([0., 0., 0.])\n",
      "tensor([4.6667, 4.6667, 4.6667])\n"
     ]
    }
   ],
   "source": [
    "W = torch.zeros(3)\n",
    "print(cost(W, x, y))\n",
    "W = torch.ones(3)\n",
    "print(cost(W, x, y))\n",
    "W = torch.full((3, ), 2)\n",
    "print(cost(W, x, y))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "outputs": [
    {
     "data": {
      "text/plain": "[<matplotlib.lines.Line2D at 0x29dc02ecfa0>]"
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlc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KlFsC0vJG8gIqnAIGC9xVGA7y9TbAWKgKXGGI/IBfwDeAywW5yjKQZYIiKbHAu9u4THFbiI/EdEdjTxNQ3AGPOEMSYZmA884Cm5HJ95gsZ/+s73pFwewqlFsNUPiUg74CPgkTP+BWoZY0yD4zJmZ2CYiPSzOBIicjVQZIzZZHWWs7jEGDOYxkuI94vIWFf80BatyOMOxphJTn50AfA58Hs3xvne+XKJyEzgamCiacXB9c34/bKaLoLdTCISTGN5zzfGfGx1njMZY06KyHIa7yFYfRP4EmCqiFwJhAEdROQdY8ytFucCwBhz2LEtEpFPaLyk2OJ7Ux53Bn4uIpJ22u5UYI9VWU4nIlOAXwFTjTFVVufxULoIdjOIiABzgd3GmL9bnecUEYk5NcpKRNoAk/CAv4fGmF8bYzobY1Jp/LP1taeUt4i0FZH2p14Dl+Gi/+F5VYEDTzsuD2yn8TfBI4ZWAS8C7YGljmFCr1odCEBErhWRfGAk8LmIfGVVFsdN3lOLYO8GPvCERbBF5F1gLdBTRPJF5C6rMzlcAtwGTHD8mdrqOLu0WgLwjePv4EYar4F71JA9DxQHrBKRbcAG4HNjzJeu+MH6KL1SSnkpbzsDV0op5aAFrpRSXkoLXCmlvJQWuFJKeSktcKWU8lJa4Eop5aW0wJVSykv9PzJX12+P6xFdAAAAAElFTkSuQmCC\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# What does cost(W) look like?\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "rng = torch.arange(-3., 5., 0.01)\n",
    "inp = torch.stack([rng]*3)\n",
    "\n",
    "output = cost(inp, x, y)\n",
    "plt.plot(rng.numpy(), output.numpy())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "params argument given to the optimizer should be an iterable of Tensors or dicts, but got torch.LongTensor",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mTypeError\u001B[0m                                 Traceback (most recent call last)",
      "Input \u001B[1;32mIn [70]\u001B[0m, in \u001B[0;36m<cell line: 1>\u001B[1;34m()\u001B[0m\n\u001B[1;32m----> 1\u001B[0m \u001B[43mtorch\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43moptim\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mSGD\u001B[49m\u001B[43m(\u001B[49m\u001B[43mW\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mD:\\Users\\Min\\Anaconda3\\envs\\torch\\lib\\site-packages\\torch\\optim\\sgd.py:105\u001B[0m, in \u001B[0;36mSGD.__init__\u001B[1;34m(self, params, lr, momentum, dampening, weight_decay, nesterov, maximize, foreach)\u001B[0m\n\u001B[0;32m    103\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m nesterov \u001B[38;5;129;01mand\u001B[39;00m (momentum \u001B[38;5;241m<\u001B[39m\u001B[38;5;241m=\u001B[39m \u001B[38;5;241m0\u001B[39m \u001B[38;5;129;01mor\u001B[39;00m dampening \u001B[38;5;241m!=\u001B[39m \u001B[38;5;241m0\u001B[39m):\n\u001B[0;32m    104\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mNesterov momentum requires a momentum and zero dampening\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m--> 105\u001B[0m \u001B[38;5;28;43msuper\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mSGD\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[43m)\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[38;5;21;43m__init__\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mparams\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mdefaults\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mD:\\Users\\Min\\Anaconda3\\envs\\torch\\lib\\site-packages\\torch\\optim\\optimizer.py:40\u001B[0m, in \u001B[0;36mOptimizer.__init__\u001B[1;34m(self, params, defaults)\u001B[0m\n\u001B[0;32m     37\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_hook_for_profile()\n\u001B[0;32m     39\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(params, torch\u001B[38;5;241m.\u001B[39mTensor):\n\u001B[1;32m---> 40\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mTypeError\u001B[39;00m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mparams argument given to the optimizer should be \u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m     41\u001B[0m                     \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124man iterable of Tensors or dicts, but got \u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;241m+\u001B[39m\n\u001B[0;32m     42\u001B[0m                     torch\u001B[38;5;241m.\u001B[39mtypename(params))\n\u001B[0;32m     44\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mstate \u001B[38;5;241m=\u001B[39m defaultdict(\u001B[38;5;28mdict\u001B[39m)\n\u001B[0;32m     45\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mparam_groups \u001B[38;5;241m=\u001B[39m []\n",
      "\u001B[1;31mTypeError\u001B[0m: params argument given to the optimizer should be an iterable of Tensors or dicts, but got torch.LongTensor"
     ]
    }
   ],
   "source": [
    "torch.optim.SGD(W)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}